/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import model.IntersectionInfo;
import view.Display;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import ucm.UCController;

/**
 * Simulator main class for the GUI traffic light simulation.
 * @author Chiaki Sato
 * @since J2SDK 1.6
 * @version 1.0
 */
public class Simulator {

    // private instance valiables
    private static Display oDisplay;
    private static IntersectionInfo oIntersectionInfo;
    private static Traffic oTraffic;

    /**
     * Public static main function to start and continue the program.
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        // create intersection information class object (Model)
        oIntersectionInfo = new IntersectionInfo();

        // create traffic flow class object (Controller)
        oTraffic = new Traffic(oIntersectionInfo);

        // create display class object (View)
        oDisplay = new Display(oIntersectionInfo, oTraffic);

        // set Display object to oTraffic
        oTraffic.setDisplay(oDisplay);

        // add event listner for menu and button contorls
        oDisplay.addListenerStartSimulationMenu(new UCComponentListener());
        oDisplay.addListenerEndSimulationMenu(new UCComponentListener());
        oDisplay.addListenerExitSimulationMenu(new UCComponentListener());
        oDisplay.addListenerSetInfoButton(new UCComponentListener());
        oDisplay.addListenerStartButton(new UCComponentListener());
        oDisplay.addListenerEndButton(new UCComponentListener());

        // set visible simulator display
        oDisplay.setVisible(true);

    }

    /**
     * Use case control components listener class.
     * @author Chiaki Sato
     * @since J2SDK 1.6
     * @version 1.0
     */
    public static class UCComponentListener implements ActionListener  {

        /**
         * Public actionPerformed function to delver events into the handers.
         * @param e the action event object
         */
        public void actionPerformed(ActionEvent e) {
            UCController command = (UCController)e.getSource();
            command.run();
        }
    }

}
